#include "typeimport.h"

#include <QFile>
#include <QtXml>
#include <QDebug>
#include <QDomElement>
#include <QDomDocument>

static QMap<QString, int> existsTypesList;

TypeImport::TypeImport(QObject *parent) : QObject(parent)
{
    hash["int8"]="int";
    hash["int16"]="short";
    hash["int32"]="int";
    hash["int64"]="int";
    hash["float32"]="float";
    hash["float64"]="float";
    hash["uint8"]="uint";
    hash["uint16"]="ushort";
    hash["uint32"]="uint";
    hash["uint64"]="uint";
}

TypeImport::~TypeImport()
{

}

void TypeImport::clearDataTypeMap()
{
    existsTypesList.clear();
}


bool TypeImport::getTypeList_64(const QDomNode &node)
{
    if (node.toElement().tagName() != "File"&&node.toElement().tagName() != "Package")
        return false;

    QDomElement element = node.firstChild().toElement();

    if(element.tagName() != "declarations")
    {
        return false;
    }

    QDomNodeList items = element.childNodes();

    for (int i = 0;i < items.count();i++)
    {
        element = items.at(i).toElement();

        if(element.isNull() || element.tagName() != "Type" || !element.hasAttribute("name"))
            continue;

        DataTypeDefine::DataType type;
        type.node=element;

        if(parseTypes(type,type.node.toElement()))
        {
            m_datas.append(type);
        }

        //typeList.append(element);//添加所有数据类型节点

    }

    return true;

}

bool TypeImport::saveTypeList_64(const QString & filePath,DataTypeDefine::DataTypeList &datas/*,QList<QDomNode> &typeList*/)
{
    QFile file(filePath);

    //默认模型文件不存在时
    if (!file.open(QFile::ReadOnly| QFile::Text))
    {
        if (!file.open(QFile::WriteOnly| QFile::Text|QFile::Truncate))
        {
            return false;
        }

        QDomDocument doc;

        QDomProcessingInstruction instruction;

        instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
        doc.appendChild(instruction);

        QDomElement root = doc.documentElement();
        if(root.isNull())
        {
            root = doc.createElement("File");
            root.setAttribute("Type","comm");

            QDomElement declarations = doc.createElement("declarations");

            for (int i = 0;i < datas.size();i++)
            {
                QDomNode typeNode=datas[i].node;
                QString tname = typeNode.toElement().attribute("name");
                if(existsTypesList.find(tname) != existsTypesList.end()){
                    continue;
                }
                existsTypesList.insert(tname, 1);
                typeListProcess_64(datas[i],doc);

                declarations.appendChild(typeNode);
            }

            root.appendChild(declarations);
        }

        doc.appendChild(root);

        QTextStream stream( &file );
        stream.setCodec("utf-8");
        doc.save(stream,2,QDomNode::EncodingFromTextStream);

        file.close();
    }
    else {

        QDomDocument doc;

        if(!doc.setContent(&file))
        {
            file.close();
            return false;
        }

        file.close();

        QDomElement root = doc.documentElement();
        if(root.tagName()!="File")
        {
            return false;
        }

        QDomElement declarations = root.firstChild().toElement();
        if(declarations.tagName()!="declarations")
            return false;

        for (int i = 0;i < datas.size();i++)
        {
            QDomNode typeNode=datas[i].node;
            QString tname = typeNode.toElement().attribute("name");
            if(existsTypesList.find(tname) != existsTypesList.end()){
                continue;
            }
            existsTypesList.insert(tname, 1);

            typeListProcess_64(datas[i],doc);

            declarations.appendChild(datas[i].node);
        }


        if(file.open(QFile::WriteOnly|QFile::Truncate))
        {
            QTextStream stream( &file );
            stream.setCodec("utf-8");
            doc.save(stream,2,QDomNode::EncodingFromTextStream);
        }

        file.close();
    }

    return true;
}

void TypeImport::typeListProcess_64(DataTypeDefine::DataType &type,/*QDomNode &typeNode,*/QDomDocument &doc)
{
    QDomNode definitionNode=type.node.firstChild();

    QDomNode pragmasNode=definitionNode.nextSibling();

    QDomNode idNode=pragmasNode.firstChild();

    QDomNode commentNode=idNode.firstChild();

    QString tagName=definitionNode.firstChild().toElement().tagName();

    QString oid;//oid
    QString comment;//注释   

    oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

    if(!commentNode.isNull())
        comment=commentNode.toElement().text();

    type.node.removeChild(pragmasNode);

    QDomElement oidEle=doc.createElement("oid");
    oidEle.setAttribute("value",oid);
    type.node.appendChild(oidEle);

    if(!comment.isEmpty())
    {
        QDomElement pragmasEle=doc.createElement("pragmas");
        type.node.appendChild(pragmasEle);

        QDomElement commentEle=doc.createElement("comment");
        commentEle.setAttribute("value",comment);
        pragmasEle.appendChild(commentEle);
    }

    //处理引用包中的数据类型的数据类型
    if(tagName=="NamedType")
    {
        QDomNode typeRefNode=definitionNode.firstChild().firstChild().firstChild();

        if(typeRefNode.toElement().tagName()=="TypeRef"&&typeRefNode.toElement().attribute("name").contains("::"))
        {
            QString name=typeRefNode.toElement().attribute("name");
            QStringList list=name.split("::");
            name=list.at(list.size()-1);
            typeRefNode.toElement().setAttribute("name",name);
        }
    }

    //结构体
    if(tagName=="Struct")
    {
        QDomNodeList fieldList=definitionNode.firstChild().firstChild().childNodes();

        for(int j=0;j<fieldList.size();j++)
        {
            QDomNode fieldNode=fieldList.at(j);

            pragmasNode=fieldNode.firstChild().nextSibling();
            idNode=pragmasNode.firstChild();
            commentNode=idNode.firstChild();

            oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

            if(!commentNode.isNull())
                comment=commentNode.toElement().text();

            fieldNode.removeChild(pragmasNode);

            QDomElement oidEle=doc.createElement("oid");
            oidEle.setAttribute("value",oid);
            fieldNode.appendChild(oidEle);

            if(!comment.isEmpty())
            {
                QDomElement pragmasEle=doc.createElement("pragmas");
                fieldNode.appendChild(pragmasEle);

                QDomElement commentEle=doc.createElement("comment");
                commentEle.setAttribute("value",comment);
                pragmasEle.appendChild(commentEle);
            }

            fieldList.at(j)=fieldNode;
        }
    }

    //结构体数组中结构体元素的oid
    if(tagName=="Table")
    {
        QDomNode index=definitionNode.firstChild().firstChild().firstChild();

        if(index.toElement().tagName()=="Struct")
        {
            QDomNode fieldsNode=index.firstChild();

            QDomNodeList nodeList=fieldsNode.childNodes();

            for(int i=0;i<nodeList.size();i++)
            {
                QDomNode node=nodeList.at(i);

                 QDomNodeList fieldChild=node.childNodes();

                 for(int i=0;i<fieldChild.size();i++)
                 {
                     QDomNode childNode=fieldChild.at(i);

                     if(childNode.toElement().tagName()=="pragmas")
                     {
                         QDomNode fieldOid=childNode;

                         fieldOid.toElement().setTagName("oid");

                         fieldOid.toElement().setAttribute("value",QUuid::createUuid().toString(QUuid::WithoutBraces));

                         fieldOid.removeChild(fieldOid.firstChild());
                     }
                 }
            }
        }
    }

    typeMapping(type);
}

bool TypeImport::readDataTypeFile(QFile &file,const QDomNode &root)//修改了参数
{
    m_datas.clear();

    if (root.toElement().tagName() != "File"&&root.toElement().tagName() != "Package")//适配
        return false;

    QDomElement element = root.firstChild().toElement();


    if(element.tagName() != "declarations")
    {
        return false;
    }

    QDomNodeList items = element.childNodes();
    for (int i = 0;i < items.count();i++)
    {
        QDomElement item = items.at(i).toElement();
        //parseTypes(/*file,*/item);
    }

    return true;
}

void TypeImport::typeMapping(/*QFile &file,*/DataTypeDefine::DataType &data)
{
//    QHash<QString,QString> hash;
//    hash["int8"]="int";
//    hash["int16"]="short";
//    hash["int32"]="int";
//    hash["int64"]="int";
//    hash["float32"]="float";
//    hash["float64"]="float";
//    hash["uint8"]="uint";
//    hash["uint16"]="ushort";
//    hash["uint32"]="uint";
//    hash["uint64"]="uint";

//    for (int i = 0;i < datas.size();i++)
//    {
        typeConvert(hash,data);//数据类型转换
        //oidConvert(datas[i]);//oid转换
//    }

}

bool TypeImport::saveDataTypeFile(const QString & filePath, const DataTypeDefine::DataTypeList &datas)
{
    QFile file(filePath);
    if (!file.open(QFile::ReadOnly| QFile::Text))
    {
        qDebug()<<"write new typefile.";
        if (!file.open(QFile::WriteOnly| QFile::Text|QFile::Truncate))
        {
            return false;
        }

        QDomDocument doc;

        QDomProcessingInstruction instruction;

        instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
        doc.appendChild(instruction);

        QDomElement root = doc.documentElement();
        if(root.isNull())
        {
            root = doc.createElement("File");
            root.setAttribute("Type","comm");

            QDomElement declarations = doc.createElement("declarations");

            for (int i = 0;i < datas.size();i++)
            {
                saveTypes(declarations,datas.at(i),doc);
            }

            root.appendChild(declarations);
        }

        doc.appendChild(root);

        QTextStream stream( &file );
        stream.setCodec("utf-8");
        doc.save(stream,2,QDomNode::EncodingFromTextStream);

        file.close();
    }
    else {

        QDomDocument doc;
        qDebug()<<"append typefile.";

        if(!doc.setContent(&file))
        {
            file.close();
            return false;
        }

        file.close();

        QDomElement root = doc.documentElement();
        if(root.tagName()!="File")
        {
            return false;
        }

        QDomElement declarations = root.firstChild().toElement();
        if(declarations.tagName()!="declarations")
            return false;

        for (int i = 0;i < datas.size();i++)
        {
            saveTypes(declarations,datas.at(i),doc);
        }


        if(file.open(QFile::WriteOnly|QFile::Truncate))
        {
            QTextStream stream( &file );
            stream.setCodec("utf-8");
            doc.save(stream,2,QDomNode::EncodingFromTextStream);
        }

        file.close();
    }

    return true;
}

bool TypeImport::parseTypes(DataTypeDefine::DataType &type,const QDomElement &element)
{
    QString name = element.attribute("name");

    //报告imported
    if(element.hasAttribute("external")&&element.attribute("external")=="imported")
    {
        logList.append(QString("数据类型")+name+QString("为imported类型，无法导入"));
//        file.close();
        deleteTypes.append(name);
        return false;

    }

    QDomNode defNode;
    QDomNode idNode;

    QString oid;
    QString comment;

    if(!element.hasChildNodes())
    {
//        file.close();
        return false;
    }

    QDomNodeList childNodeList = element.childNodes();

    defNode = element.firstChild();

    oid = getOid(defNode);

    comment = getComment(defNode.nextSibling().firstChild());//适配SCADE格式

    if(!defNode.hasChildNodes())
    {
//        file.close();
        return false;
    }

    QDomElement typeElement = defNode.firstChild().toElement();

    QString tagName = typeElement.tagName();

    //报告枚举
    if(tagName == "Enum")
    {
        logList.append(QString("数据类型")+name+QString("为枚举类型，无法导入"));
        deleteTypes.append(name);
        //file.close();
        return false;
    }

    if(tagName == "NamedType")
    {
        //报告null
        if(typeElement.firstChild().firstChild().toElement().tagName()=="NullRef")
        {
            logList.append(QString("数据类型")+name+QString("为null类型，无法导入"));
            deleteTypes.append(name);
            //file.close();
            return false;
        }

        parseNormalData(type,typeElement,name,oid,comment);
    }

    if(tagName == "Struct")
    {
        parseStructData(type,typeElement,name,oid,comment);
    }

    if(tagName == "Table")
    {
        parseArrayData(type,typeElement,name,oid,comment);
    }

    return true;
}


void TypeImport::parseNormalData(DataTypeDefine::DataType &type,const QDomElement &element, const QString &typeName, const QString &oid, const QString &comment)
{
//    DataTypeDefine::DataType data;
    QString definition;

    if(!element.hasChildNodes() || !element.firstChild().hasChildNodes())
        return;

    QDomNode normalNode = element.firstChild().firstChild();

    QDomElement normalElement = normalNode.toElement();

    QString tagName = normalElement.tagName();
    if(tagName == "TypeRef" && normalElement.hasAttribute("name"))
    {
        definition = normalElement.attribute("name");
    }
    else
    {
        return;

    }

    type.name = typeName;
    type.definition = definition;
    type.comments = comment;
    type.oid = oid;
    type.isArray = false;
    type.isStructure = false;

    //m_datas.append(type);
}

void TypeImport::parseArrayData(DataTypeDefine::DataType &type,const QDomElement &element, const QString &typeName, const QString &oid, const QString &comment)
{
    //DataTypeDefine::DataType data;
    DataTypeDefine::DimensionArray arrayData;
    arrayData.arrayCounts.clear();

    parseArrayTable(element,arrayData);

    arrayData.arrayId = oid;
    arrayData.dimension = arrayData.arrayCounts.size();

    type.name = typeName;
    type.definition = "array";
    type.comments = comment;
    type.oid = oid;
    type.isArray = true;
    type.array = arrayData;
    type.isStructure = false;

    //m_datas.append(type);
}

void TypeImport::parseStructData(DataTypeDefine::DataType &type,const QDomElement &element, const QString &typeName, const QString &oid, const QString &comment)
{
    //DataTypeDefine::DataType data;
    QString definition;

    if(!element.hasChildNodes() || !element.firstChild().hasChildNodes() || element.firstChild().childNodes().size() < 1)
        return;

    QDomNodeList structNodes = element.firstChild().childNodes();

    DataTypeDefine::StructEleList structEleList;
    for (int i = 0; i < structNodes.size(); i++)
    {
        QDomElement structEle = structNodes.at(i).toElement();
        structEleList.append(parseStructElementData(structEle,oid));

    }

    type.name = typeName;
    type.definition = "<structure>";
    type.comments = comment;
    type.oid = oid;
    type.isArray = false;
    type.isStructure = true;
    type.structElements = structEleList;

    //m_datas.append(type);
}

void TypeImport::parseArrayTable(const QDomElement &tableElement, DataTypeDefine::DimensionArray &arrayData)
{

    if(!tableElement.hasChildNodes() || !tableElement.firstChild().hasChildNodes())
        return;

    QDomNode typeNode = tableElement.firstChild();
    QDomNode tableNode = tableElement.firstChild().firstChild();
    QDomElement childTableElement = tableNode.toElement();

    if(childTableElement.tagName() == "Table")
    {
        QDomNode sizeNode = typeNode.nextSibling();
        QDomElement sizeElement = sizeNode.firstChild().toElement();
        if(sizeElement.tagName() == "ConstValue" && sizeElement.hasAttribute("value"))
        {
            QString arrayCountStr = sizeElement.attribute("value");
            int arrayCount = arrayCountStr.toInt();
            arrayData.arrayCounts.append(arrayCount);
        }

        parseArrayTable(childTableElement,arrayData);
    }
    else
    {
        QString definition;
        QDomElement normalElement = typeNode.firstChild().firstChild().firstChild().toElement();
        if(normalElement.tagName() == "TypeRef" && normalElement.hasAttribute("name"))
        {
            definition = normalElement.attribute("name");
            arrayData.arrayType = definition;
            if(hash.contains(definition))
            {
                normalElement.setAttribute("name",hash.value(definition));
            }

        }

        if(normalElement.tagName() == "NullRef")//增加null
        {
            definition = "null";
            arrayData.arrayType = definition;
        }

        QDomNode sizeNode = typeNode.nextSibling();
        QDomElement sizeElement = sizeNode.firstChild().toElement();
        if(sizeElement.tagName() == "ConstValue" && sizeElement.hasAttribute("value"))
        {
            QString arrayCountStr = sizeElement.attribute("value");
            int arrayCount = arrayCountStr.toInt();
            arrayData.arrayCounts.append(arrayCount);
        }
    }
}

DataTypeDefine::StructEle TypeImport::parseStructElementData(const QDomElement &element, const QString &structId)
{
    DataTypeDefine::StructEle structEle;

    if(element.tagName() != "Field" && !element.hasAttribute("name"))
        return structEle;

    QString elementName = element.attribute("name");

    QDomNode typeNode = element.firstChild();

    QString elementDef;

    QDomNode dataTypeNode = typeNode.firstChild().firstChild().firstChild();
    QDomElement dataTypeElement = dataTypeNode.toElement();
    if(dataTypeElement.tagName() == "TypeRef" && dataTypeElement.hasAttribute("name"))
    {
        elementDef = dataTypeElement.attribute("name");
        if(hash.contains(elementDef))
        {
            dataTypeElement.setAttribute("name",hash.value(elementDef));
        }

    }

    if(dataTypeElement.tagName() == "NullRef")//增加null
    {
        elementDef = "null";
    }

    QString elementOid = getOid(typeNode);
    QString elementComment = getComment(typeNode.nextSibling().firstChild());

    structEle.structId = structId;
    structEle.elementName = elementName;
    structEle.elementDef = elementDef;
    structEle.elementOid = elementOid;
    structEle.elementComment = elementComment;

    return structEle;
}

void TypeImport::saveTypes(QDomElement &element, const DataTypeDefine::DataType &data, QDomDocument &doc)
{
    QDomElement Type = doc.createElement("Type");
    Type.setAttribute("name",data.name);

    if(data.isArray)
    {
        saveArrayData(Type,data,doc);
    }
    else if(data.isStructure)
    {
        saveStructData(Type,data,doc);
    }
    else {
        saveNormalData(Type,data,doc);
    }

    element.appendChild(Type);
}

void TypeImport::saveNormalData(QDomElement &element, const DataTypeDefine::DataType &data, QDomDocument &doc)
{
    QDomElement definition = doc.createElement("definition");
    QDomElement NamedType = doc.createElement("NamedType");
    QDomElement type = doc.createElement("type");
    QDomElement TypeRef = doc.createElement("TypeRef");
    TypeRef.setAttribute("name",data.definition);

    type.appendChild(TypeRef);
    NamedType.appendChild(type);
    definition.appendChild(NamedType);


    QDomElement oid = doc.createElement("oid");
    oid.setAttribute("value",data.oid);

    element.appendChild(definition);
    element.appendChild(oid);

    if(!data.comments.isEmpty())
    {
        QDomElement pragmas = doc.createElement("pragmas");
        QDomElement comment = doc.createElement("comment");
        comment.setAttribute("value",data.comments);
        pragmas.appendChild(comment);
        element.appendChild(pragmas);
    }
}

void TypeImport::saveArrayData(QDomElement &element, const DataTypeDefine::DataType &data, QDomDocument &doc)
{
    QDomElement definition = doc.createElement("definition");
    QDomElement Table = doc.createElement("Table");

    DataTypeDefine::DimensionArray arrayData = data.array;

    saveArrayTable(Table,arrayData,doc);

    definition.appendChild(Table);

    QDomElement oid = doc.createElement("oid");
    oid.setAttribute("value",data.oid);

    element.appendChild(definition);
    element.appendChild(oid);

    if(!data.comments.isEmpty())
    {
        QDomElement pragmas = doc.createElement("pragmas");
        QDomElement comment = doc.createElement("comment");
        comment.setAttribute("value",data.comments);
        pragmas.appendChild(comment);
        element.appendChild(pragmas);
    }
}

void TypeImport::saveArrayTable(QDomElement &table, DataTypeDefine::DimensionArray arrayData, QDomDocument &doc)
{
    if(arrayData.arrayCounts.isEmpty())
        return;

    QDomElement size = doc.createElement("size");
    QDomElement ConstValue = doc.createElement("ConstValue");
    ConstValue.setAttribute("value",arrayData.arrayCounts.takeFirst());
    size.appendChild(ConstValue);

    if(arrayData.arrayCounts.count() > 0)
    {
        QDomElement tableType = doc.createElement("type");
        QDomElement typeTable = doc.createElement("Table");
        saveArrayTable(typeTable,arrayData,doc);
        tableType.appendChild(typeTable);
        table.appendChild(tableType);
    }
    else
    {
        QDomElement tableType = doc.createElement("type");
        QDomElement NamedType = doc.createElement("NamedType");
        QDomElement type = doc.createElement("type");
        QDomElement TypeRef = doc.createElement("TypeRef");
        TypeRef.setAttribute("name",arrayData.arrayType);
        type.appendChild(TypeRef);
        NamedType.appendChild(type);
        tableType.appendChild(NamedType);
        table.appendChild(tableType);
    }
    table.appendChild(size);
}

void TypeImport::saveStructData(QDomElement &element, const DataTypeDefine::DataType &data, QDomDocument &doc)
{
    QDomElement definition = doc.createElement("definition");

    QDomElement Struct = doc.createElement("Struct");
    QDomElement fields = doc.createElement("fields");

    DataTypeDefine::StructEleList structEles = data.structElements;
    for (int i = 0; i < structEles.size();i++)
    {
        DataTypeDefine::StructEle structEle = structEles.at(i);
        saveStructElementData(fields,structEle,doc);
    }

    Struct.appendChild(fields);
    definition.appendChild(Struct);

    QDomElement oid = doc.createElement("oid");
    oid.setAttribute("value",data.oid);

    element.appendChild(definition);
    element.appendChild(oid);

    if(!data.comments.isEmpty())
    {
        QDomElement pragmas = doc.createElement("pragmas");
        QDomElement comment = doc.createElement("comment");
        comment.setAttribute("value",data.comments);
        pragmas.appendChild(comment);
        element.appendChild(pragmas);
    }
}

void TypeImport::saveStructElementData(QDomElement &element, const DataTypeDefine::StructEle &data, QDomDocument &doc)
{
    QDomElement Field = doc.createElement("Field");
    Field.setAttribute("name",data.elementName);

    QDomElement type = doc.createElement("type");
    QDomElement NamedType = doc.createElement("NamedType");
    QDomElement typeInNamedType = doc.createElement("type");
    QDomElement TypeRef = doc.createElement("TypeRef");
    TypeRef.setAttribute("name",data.elementDef);

    typeInNamedType.appendChild(TypeRef);
    NamedType.appendChild(typeInNamedType);
    type.appendChild(NamedType);


    QDomElement oid = doc.createElement("oid");
    oid.setAttribute("value",data.elementOid);


    Field.appendChild(type);
    Field.appendChild(oid);

    if(!data.elementComment.isEmpty())
    {
        QDomElement pragmas = doc.createElement("pragmas");
        QDomElement comment = doc.createElement("comment");
        comment.setAttribute("value",data.elementComment);
        pragmas.appendChild(comment);
        Field.appendChild(pragmas);
    }

    element.appendChild(Field);
}

//获取oid，有区别
QString TypeImport::getOid(const QDomNode &defNode)
{
    QString oid;
    if(defNode.nextSibling().toElement().tagName()=="pragmas"&&defNode.nextSibling().firstChild().toElement().hasAttribute("oid"))
    {
        QDomNode idNode = defNode.nextSibling().firstChild();
        oid = idNode.toElement().attribute("oid");
    }
    return  oid;
}

//获取注释，有区别
QString TypeImport::getComment(const QDomNode &idNode)
{
    QString comment;
    if(!idNode.firstChild().isNull())
    {
        QDomNode comtNode = idNode.firstChild();

        comment = comtNode.toElement().text();
    }
    return comment;
}

//新增，进行基础数据类型转换
void TypeImport::typeConvert(/*QFile &file,*/const QHash<QString,QString> &hash, DataTypeDefine::DataType &data)
{
//    if( !file.open(QIODevice::Append | QIODevice::Text) )
//        return;

//    QTextStream out(&file);

    if(!data.isStructure&&!data.isArray&&hash.contains(data.definition))
    {
        logList.append(QString("数据类型")+data.name+QString("的数据类型发生转换：")+data.definition+QString("->")+hash.value(data.definition));
        data.node.firstChild().firstChild().firstChild().firstChild().toElement().setAttribute("name",hash.value(data.definition));
        data.definition = hash.value(data.definition);
        changeTypes.append(data.name);
    }

    if(data.isArray&&hash.contains(data.array.arrayType))
    {
        logList.append(QString("数据类型")+data.name+QString("的数组类型发生转换：")+data.array.arrayType+QString("->")+hash.value(data.array.arrayType));
        data.array.arrayType = hash.value(data.array.arrayType);
        changeTypes.append(data.name);
    }

    if(data.isStructure)
    {
        for (int i=0;i<data.structElements.size();i++)
        {
            if(hash.contains(data.structElements.at(i).elementDef))
            {
                logList.append(QString("数据类型")+data.name+QString("的结构体元素发生转换：")+data.structElements[i].elementDef+QString("->")+hash.value(data.structElements.at(i).elementDef));

                data.structElements[i].elementDef=hash.value(data.structElements.at(i).elementDef);
            }
        }
        changeTypes.append(data.name);
    }

//    file.close();

}

void TypeImport::oidConvert(DataTypeDefine::DataType &data)
{
    data.oid=QUuid::createUuid().toString(QUuid::WithoutBraces);

    if(data.isStructure)
    {
        for (int i=0;i<data.structElements.size();i++)
        {
            data.structElements[i].elementOid=QUuid::createUuid().toString(QUuid::WithoutBraces);
        }
    }
}
